package com.zeldu.exam.controller;

import com.zeldu.common.model.response.CommonCode;
import com.zeldu.common.model.response.QueryResponseResult;
import com.zeldu.common.model.response.QueryResult;
import com.zeldu.exam.pojo.StudentExam;
import com.zeldu.exam.pojo.exam;
import com.zeldu.exam.service.StudentExamService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("examstatus")
public class StudentExamController {

    @Autowired
    private StudentExamService studentExamService;

//    @RequestMapping(value = "studentexam/{student_id}",method = {RequestMethod.GET})
//    @ResponseBody
//    public StudentExam FindStudentExam(@PathVariable("student_id") Long id){
//        return studentExamService.queryBystudentId(id);
//    }


    //使用examid去查询exam——student表来读取学生考试状态
    @RequestMapping(value = "teacherexam/{exam_id}",method = {RequestMethod.GET})
    @ResponseBody
    public QueryResponseResult<StudentExam> FindTeacherExam(@PathVariable("exam_id") Long exam_id){
        List<StudentExam> list = studentExamService.queryByExamId(exam_id);
        QueryResult<StudentExam> queryResult=new QueryResult<>();
        queryResult.setList(list);
        queryResult.setTotal(list.size());
        if(list!=null){
            return  new QueryResponseResult<StudentExam>(CommonCode.SUCCESS,queryResult);
        }else {
            return  new QueryResponseResult<StudentExam>(CommonCode.FAIL,queryResult);
        }
    }

//设置分数和考试状态的---提供
    @RequestMapping(value = "setScore",method = {RequestMethod.POST})
    @ResponseBody
    public int FindTeacherExam(@RequestBody StudentExam studentExam){
        //需要id
        Long id =123L;
        return studentExamService.insertScore(studentExam);
    }

//通过studentid和examid去查询答案
    @RequestMapping(value = "finish",method = {RequestMethod.GET})
    @ResponseBody
    public String FindTeacherExam(@RequestParam("exam_id") Long exam_id,@RequestParam("student_id") Long student_id){
        System.out.print("---------------------------"+exam_id);
        return studentExamService.findContextByExamidAndStudentid(student_id,exam_id);
    }


}
